Skip to content

perf: defer API run creation until first emission upload (3/4)#1253

Merged
inimaz merged 5 commits into
masterfrom
davidberenstein1957/perf-3-lazy-api-run
Jun 29, 2026
Merged

perf: defer API run creation until first emission upload (3/4)#1253
inimaz merged 5 commits into
masterfrom
davidberenstein1957/perf-3-lazy-api-run

Conversation

@davidberenstein1957

@davidberenstein1957 davidberenstein1957 commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part 3/4 of the tracker performance stack. Depends on #1251#1252.

cc @inimaz — small, isolated API write-path change from the #1246 split.

Defers the POST /runs API call until the first emission is actually uploaded, so online trackers with API output enabled no longer block on run creation during startup:

  • CodeCarbonAPIOutput uses create_run_automatically=False
  • _ensure_api_run() creates the run lazily on first live_out / out call

Benchmarks (measured locally, offline Mac ARM, 2026-06-21)

Mocked geo/cloud/API network; measures EmissionsTracker(save_to_api=True) cold start():

Metric #1251 + #1252 + this PR Notes
API tracker start() avg 407 ms 369 ms ~9% faster — avoids blocking POST /runs at startup
Tracker __init__ / warm lifecycle unchanged unchanged No change expected — run creation deferred to first upload

Stack

  1. perf: defer tracker initialization and slim import path (1/4) #1251 — lazy initialization & import slimming
  2. perf: cache hardware detection and optimize warm-path reuse (2/4) #1252 — hardware detection cache & warm-path reuse
  3. This PR — lazy API run creation
  4. perf: speed up CLI monitor startup and fix wrapped commands (4/4) #1254 — CLI monitor startup

CI / quality

Test plan

  • Reviewer: online tracker with API output still uploads emissions correctly

Replaces

Split from #1246.

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (473351b) to head (f6ef0f0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1253   +/-   ##
=======================================
  Coverage   89.61%   89.62%           
=======================================
  Files          48       48           
  Lines        4757     4761    +4     
=======================================
+ Hits         4263     4267    +4     
  Misses        494      494           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davidberenstein1957

Copy link
Copy Markdown
Collaborator Author

@inimaz#1246 has been split into this 4-PR stack for easier review. Benchmarks in the description are measured locally (Mac ARM, 2026-06-21); pre-commit and tests pass on each branch. Please start with #1251.

@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-2-hardware-cache branch from 1f759d9 to 9d1c656 Compare June 21, 2026 14:37
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from a85be35 to 07b82eb Compare June 21, 2026 14:37
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-2-hardware-cache branch from 9d1c656 to 00817d8 Compare June 22, 2026 07:49
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from 07b82eb to 928621d Compare June 22, 2026 07:49
davidberenstein1957 and others added 2 commits June 29, 2026 08:49
Add process-level hardware setup cache, probe result caching, platform-aware
CPU backend selection, and parallel CPU/GPU setup for faster repeat runs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Import GPU/CPU probe modules before clearing caches so lru_cache state
does not leak across tests in the full suite.

Co-authored-by: Cursor <cursoragent@cursor.com>
@davidberenstein1957

Copy link
Copy Markdown
Collaborator Author

@inimaz#1251 is merged. This PR has been rebased onto the updated stack. CI and local tests pass — ready for your review.

@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from 928621d to 85a0b1f Compare June 29, 2026 06:53
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-2-hardware-cache branch from 00817d8 to 31dc256 Compare June 29, 2026 06:53
davidberenstein1957 and others added 2 commits June 29, 2026 09:37
Cover scalar GPU id normalization, defensive error paths, power gadget
setup, and fallback tracking branches missing from the PR patch report.

Co-authored-by: Cursor <cursoragent@cursor.com>
Skip POST /runs during tracker startup and create the run lazily on the
first live_out/out call when an experiment id is configured.

Co-authored-by: Cursor <cursoragent@cursor.com>
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from 85a0b1f to e8e07e9 Compare June 29, 2026 07:37
Base automatically changed from davidberenstein1957/perf-2-hardware-cache to master June 29, 2026 12:10

@inimaz inimaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this will make it much faster the first setup of the client. Thanks @davidberenstein1957 !

@inimaz inimaz merged commit 553e852 into master Jun 29, 2026
13 checks passed
@inimaz inimaz deleted the davidberenstein1957/perf-3-lazy-api-run branch June 29, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants